home *** CD-ROM | disk | FTP | other *** search
/ Risc World 5 / Risc World 5.iso / SOFTWARE / Issue3 / Games / xrick / !xrick / src / c / e_them < prev    next >
Text File  |  2004-06-24  |  17KB  |  728 lines

  1. /*
  2.  * xrick/src/e_them.c
  3.  *
  4.  * Copyright (C) 1998-2002 BigOrno (bigorno@bigorno.net). All rights reserved.
  5.  *
  6.  * The use and distribution terms for this software are contained in the file
  7.  * named README, which can be found in the root of this distribution. By
  8.  * using this software in any fashion, you are agreeing to be bound by the
  9.  * terms of this license.
  10.  *
  11.  * You must not remove this notice, or any other, from this software.
  12.  */
  13.  
  14. #include "system.h"
  15. #include "game.h"
  16. #include "ents.h"
  17. #include "e_them.h"
  18.  
  19. #include "e_rick.h"
  20. #include "e_bomb.h"
  21. #include "e_bullet.h"
  22. #include "maps.h"
  23. #include "util.h"
  24.  
  25. #define TYPE_1A (0x00)
  26. #define TYPE_1B (0xff)
  27.  
  28. /*
  29.  * public vars
  30.  */
  31. U32 e_them_rndseed = 0;
  32.  
  33. /*
  34.  * local vars
  35.  */
  36. static U16 e_them_rndnbr = 0;
  37.  
  38. /*
  39.  * Check if entity boxtests with a lethal e_them i.e. something lethal
  40.  * in slot 0 and 4 to 8.
  41.  *
  42.  * ASM 122E
  43.  *
  44.  * e: entity slot number.
  45.  * ret: TRUE/boxtests, FALSE/not
  46.  */
  47. U8
  48. u_themtest(U8 e)
  49. {
  50.   U8 i;
  51.  
  52.   if ((ent_ents[0].n & ENT_LETHAL) && u_boxtest(e, 0))
  53.     return TRUE;
  54.  
  55.   for (i = 4; i < 9; i++)
  56.     if ((ent_ents[i].n & ENT_LETHAL) && u_boxtest(e, i))
  57.       return TRUE;
  58.  
  59.   return FALSE;
  60. }
  61.  
  62.  
  63. /*
  64.  * Go zombie
  65.  *
  66.  * ASM 237B
  67.  */
  68. void
  69. e_them_gozombie(U8 e)
  70. {
  71. #define offsx c1
  72.   ent_ents[e].n = 0x47;  /* zombie entity */
  73.   ent_ents[e].front = TRUE;
  74.   ent_ents[e].offsy = -0x0400;
  75. #ifdef ENABLE_SOUND
  76.   syssnd_play(WAV_DIE, 1);
  77. #endif
  78.   game_score += 50;
  79.   if (ent_ents[e].flags & ENT_FLG_ONCE) {
  80.     /* make sure entity won't be activated again */
  81.     map_marks[ent_ents[e].mark].ent |= MAP_MARK_NACT;
  82.   }
  83.   ent_ents[e].offsx = (ent_ents[e].x >= 0x80 ? -0x02 : 0x02);
  84. #undef offsx
  85. }
  86.  
  87.  
  88. /*
  89.  * Action sub-function for e_them _t1a and _t1b
  90.  *
  91.  * Those two types move horizontally, and fall if they have to.
  92.  * Type 1a moves horizontally over a given distance and then
  93.  * u-turns and repeats; type 1b is more subtle as it does u-turns
  94.  * in order to move horizontally towards rick.
  95.  *
  96.  * ASM 2242
  97.  */
  98. void
  99. e_them_t1_action2(U8 e, U8 type)
  100. {
  101. #define offsx c1
  102. #define step_count c2
  103.   U32 i;
  104.   S16 x, y;
  105.   U8 env0, env1;
  106.  
  107.   /* by default, try vertical move. calculate new y */
  108.   i = (ent_ents[e].y << 8) + ent_ents[e].offsy + ent_ents[e].ylow;
  109.   y = i >> 8;
  110.  
  111.   /* deactivate if outside vertical boundaries */
  112.   /* no need to test zero since e_them _t1a/b don't go up */
  113.   /* FIXME what if they got scrolled out ? */
  114.   if (y > 0x140) {
  115.     ent_ents[e].n = 0;
  116.     return;
  117.   }
  118.  
  119.   /* test environment */
  120.   u_envtest(ent_ents[e].x, y, FALSE, &env0, &env1);
  121.  
  122.   if (!(env1 & (MAP_EFLG_VERT|MAP_EFLG_SOLID|MAP_EFLG_SPAD|MAP_EFLG_WAYUP))) {
  123.     /* vertical move possible: falling */
  124.     if (env1 & MAP_EFLG_LETHAL) {
  125.       /* lethal entities kill e_them */
  126.       e_them_gozombie(e);
  127.       return;
  128.     }
  129.     /* save, cleanup and return */
  130.     ent_ents[e].y = y;
  131.     ent_ents[e].ylow = i;
  132.     ent_ents[e].offsy += 0x0080;
  133.     if (ent_ents[e].offsy > 0x0800)
  134.       ent_ents[e].offsy = 0x0800;
  135.     return;
  136.   }
  137.  
  138.   /* vertical move not possible. calculate new sprite */
  139.   ent_ents[e].sprite = ent_ents[e].sprbase
  140.     + ent_sprseq[(ent_ents[e].x & 0x1c) >> 3]
  141.     + (ent_ents[e].offsx < 0 ? 0x03 : 0x00);
  142.  
  143.   /* reset offsy */
  144.   ent_ents[e].offsy = 0x0080;
  145.  
  146.   /* align to ground */
  147.   ent_ents[e].y &= 0xfff8;
  148.   ent_ents[e].y |= 0x0003;
  149.  
  150.   /* latency: if not zero then decrease and return */
  151.   if (ent_ents[e].latency > 0) {
  152.     ent_ents[e].latency--;
  153.     return;
  154.   }
  155.  
  156.   /* horizontal move. calculate new x */
  157.   if (ent_ents[e].offsx == 0)  /* not supposed to move -> don't */
  158.     return;
  159.  
  160.   x = ent_ents[e].x + ent_ents[e].offsx;
  161.   if (ent_ents[e].x < 0 || ent_ents[e].x > 0xe8) {
  162.     /*  U-turn and return if reaching horizontal boundaries */
  163.     ent_ents[e].step_count = 0;
  164.     ent_ents[e].offsx = -ent_ents[e].offsx;
  165.     return;
  166.   }
  167.  
  168.   /* test environment */
  169.   u_envtest(x, ent_ents[e].y, FALSE, &env0, &env1);
  170.  
  171.   if (env1 & (MAP_EFLG_VERT|MAP_EFLG_SOLID|MAP_EFLG_SPAD|MAP_EFLG_WAYUP)) {
  172.     /* horizontal move not possible: u-turn and return */
  173.     ent_ents[e].step_count = 0;
  174.     ent_ents[e].offsx = -ent_ents[e].offsx;
  175.     return;
  176.   }
  177.  
  178.   /* horizontal move possible */
  179.   if (env1 & MAP_EFLG_LETHAL) {
  180.     /* lethal entities kill e_them */
  181.     e_them_gozombie(e);
  182.     return;
  183.   }
  184.  
  185.   /* save */
  186.   ent_ents[e].x = x;
  187.  
  188.   /* depending on type, */
  189.   if (type == TYPE_1B) {
  190.     /* set direction to move horizontally towards rick */
  191.     if ((ent_ents[e].x & 0x1e) != 0x10)  /* prevents too frequent u-turns */
  192.       return;
  193.     ent_ents[e].offsx = (ent_ents[e].x < E_RICK_ENT.x) ? 0x02 : -0x02;
  194.     return;
  195.   }
  196.   else {
  197.     /* set direction according to step counter */
  198.     ent_ents[e].step_count++;
  199.     /* FIXME why trig_x (b16) ?? */
  200.     if ((ent_ents[e].trig_x >> 1) > ent_ents[e].step_count)
  201.       return;
  202.   }
  203.  
  204.   /* type is 1A and step counter reached its limit: u-turn */
  205.   ent_ents[e].step_count = 0;
  206.   ent_ents[e].offsx = -ent_ents[e].offsx;
  207. #undef offsx
  208. #undef step_count
  209. }
  210.  
  211.  
  212. /*
  213.  * ASM 21CF
  214.  */
  215. void
  216. e_them_t1_action(U8 e, U8 type)
  217. {
  218.   e_them_t1_action2(e, type);
  219.  
  220.   /* lethal entities kill them */
  221.   if (u_themtest(e)) {
  222.     e_them_gozombie(e);
  223.     return;
  224.   }
  225.  
  226.   /* bullet kills them */
  227.   if (E_BULLET_ENT.n &&
  228.       u_fboxtest(e, E_BULLET_ENT.x + (e_bullet_offsx < 0 ? 0 : 0x18),
  229.          E_BULLET_ENT.y)) {
  230.     E_BULLET_ENT.n = 0;
  231.     e_them_gozombie(e);
  232.     return;
  233.   }
  234.  
  235.   /* bomb kills them */
  236.   if (e_bomb_lethal && e_bomb_hit(e)) {
  237.     e_them_gozombie(e);
  238.     return;
  239.   }
  240.  
  241.   /* rick stops them */
  242.   if (E_RICK_STTST(E_RICK_STSTOP) &&
  243.       u_fboxtest(e, e_rick_stop_x, e_rick_stop_y))
  244.     ent_ents[e].latency = 0x14;
  245.  
  246.   /* they kill rick */
  247.   if (e_rick_boxtest(e))
  248.     e_rick_gozombie();
  249. }
  250.  
  251.  
  252. /*
  253.  * Action function for e_them _t1a type (stays within boundaries)
  254.  *
  255.  * ASM 2452
  256.  */
  257. void
  258. e_them_t1a_action(U8 e)
  259. {
  260.   e_them_t1_action(e, TYPE_1A);
  261. }
  262.  
  263.  
  264. /*
  265.  * Action function for e_them _t1b type (runs for rick)
  266.  *
  267.  * ASM 21CA
  268.  */
  269. void
  270. e_them_t1b_action(U8 e)
  271. {
  272.   e_them_t1_action(e, TYPE_1B);
  273. }
  274.  
  275.  
  276. /*
  277.  * Action function for e_them _z (zombie) type
  278.  *
  279.  * ASM 23B8
  280.  */
  281. void
  282. e_them_z_action(U8 e)
  283. {
  284. #define offsx c1
  285.   U32 i;
  286.  
  287.   /* calc new sprite */
  288.   ent_ents[e].sprite = ent_ents[e].sprbase
  289.     + ((ent_ents[e].x & 0x04) ? 0x07 : 0x06);
  290.  
  291.   /* calc new y */
  292.   i = (ent_ents[e].y << 8) + ent_ents[e].offsy + ent_ents[e].ylow;
  293.  
  294.   /* deactivate if out of vertical boundaries */
  295.   if (ent_ents[e].y < 0 || ent_ents[e].y > 0x0140) {
  296.     ent_ents[e].n = 0;
  297.     return;
  298.   }
  299.  
  300.   /* save */
  301.   ent_ents[e].offsy += 0x0080;
  302.   ent_ents[e].ylow = i;
  303.   ent_ents[e].y = i >> 8;
  304.  
  305.   /* calc new x */
  306.   ent_ents[e].x += ent_ents[e].offsx;
  307.  
  308.   /* must stay within horizontal boundaries */
  309.   if (ent_ents[e].x < 0)
  310.     ent_ents[e].x = 0;
  311.   if (ent_ents[e].x > 0xe8)
  312.     ent_ents[e].x = 0xe8;
  313. #undef offsx
  314. }
  315.  
  316.  
  317. /*
  318.  * Action sub-function for e_them _t2.
  319.  *
  320.  * Must document what it does.
  321.  *
  322.  * ASM 2792
  323.  */
  324. void
  325. e_them_t2_action2(U8 e)
  326. {
  327. #define flgclmb c1
  328. #define offsx c2
  329.   U32 i;
  330.   S16 x, y, yd;
  331.   U8 env0, env1;
  332.  
  333.   /*
  334.    * vars required by the Black Magic (tm) performance at the
  335.    * end of this function.
  336.    */
  337.   static U16 bx;
  338.   static U8 *bl = (U8 *)&bx;
  339.   static U8 *bh = (U8 *)&bx + 1;
  340.   static U16 cx;
  341.   static U8 *cl = (U8 *)&cx;
  342.   static U8 *ch = (U8 *)&cx + 1;
  343.   static U16 *sl = (U16 *)&e_them_rndseed;
  344.   static U16 *sh = (U16 *)&e_them_rndseed + 2;
  345.  
  346.   /*sys_printf("e_them_t2 ------------------------------\n");*/
  347.  
  348.   /* latency: if not zero then decrease */
  349.   if (ent_ents[e].latency > 0) ent_ents[e].latency--;
  350.  
  351.   /* climbing? */
  352.   if (ent_ents[e].flgclmb != TRUE) goto climbing_not;
  353.  
  354.   /* CLIMBING */
  355.  
  356.   /*sys_printf("e_them_t2 climbing\n");*/
  357.  
  358.   /* latency: if not zero then return */
  359.   if (ent_ents[e].latency > 0) return;
  360.  
  361.   /* calc new sprite */
  362.   ent_ents[e].sprite = ent_ents[e].sprbase + 0x08 +
  363.     (((ent_ents[e].x ^ ent_ents[e].y) & 0x04) ? 1 : 0);
  364.  
  365.   /* reached rick's level? */
  366.   if ((ent_ents[e].y & 0xfe) != (E_RICK_ENT.y & 0xfe)) goto ymove;
  367.  
  368.   xmove:
  369.     /* calc new x and test environment */
  370.     ent_ents[e].offsx = (ent_ents[e].x < E_RICK_ENT.x) ? 0x02 : -0x02;
  371.     x = ent_ents[e].x + ent_ents[e].offsx;
  372.     u_envtest(x, ent_ents[e].y, FALSE, &env0, &env1);
  373.     if (env1 & (MAP_EFLG_SOLID|MAP_EFLG_SPAD|MAP_EFLG_WAYUP))
  374.       return;
  375.     if (env1 & MAP_EFLG_LETHAL) {
  376.       e_them_gozombie(e);
  377.       return;
  378.     }
  379.     ent_ents[e].x = x;
  380.     if (env1 & (MAP_EFLG_VERT|MAP_EFLG_CLIMB))  /* still climbing */
  381.       return;
  382.     goto climbing_not;  /* not climbing anymore */
  383.  
  384.   ymove:
  385.     /* calc new y and test environment */
  386.     yd = ent_ents[e].y < E_RICK_ENT.y ? 0x02 : -0x02;
  387.     y = ent_ents[e].y + yd;
  388.     if (y < 0 || y > 0x0140) {
  389.       ent_ents[e].n = 0;
  390.       return;
  391.     }
  392.     u_envtest(ent_ents[e].x, y, FALSE, &env0, &env1);
  393.     if (env1 & (MAP_EFLG_SOLID|MAP_EFLG_SPAD|MAP_EFLG_WAYUP)) {
  394.       if (yd < 0)
  395.     goto xmove;  /* can't go up */
  396.       else
  397.     goto climbing_not;  /* can't go down */
  398.     }
  399.     /* can move */
  400.     ent_ents[e].y = y;
  401.     if (env1 & (MAP_EFLG_VERT|MAP_EFLG_CLIMB))  /* still climbing */
  402.       return;
  403.  
  404.     /* NOT CLIMBING */
  405.  
  406.  climbing_not:
  407.     /*sys_printf("e_them_t2 climbing NOT\n");*/
  408.  
  409.     ent_ents[e].flgclmb = FALSE;  /* not climbing */
  410.  
  411.     /* calc new y (falling) and test environment */
  412.     i = (ent_ents[e].y << 8) + ent_ents[e].offsy + ent_ents[e].ylow;
  413.     y = i >> 8;
  414.     u_envtest(ent_ents[e].x, y, FALSE, &env0, &env1);
  415.     if (!(env1 & (MAP_EFLG_SOLID|MAP_EFLG_SPAD|MAP_EFLG_WAYUP))) {
  416.       /*sys_printf("e_them_t2 y move OK\n");*/
  417.       /* can go there */
  418.       if (env1 & MAP_EFLG_LETHAL) {
  419.     e_them_gozombie(e);
  420.     return;
  421.       }
  422.       if (y > 0x0140) {  /* deactivate if outside */
  423.     ent_ents[e].n = 0;
  424.     return;
  425.       }
  426.       if (!(env1 & MAP_EFLG_VERT)) {
  427.     /* save */
  428.     ent_ents[e].y = y;
  429.     ent_ents[e].ylow = i;
  430.     ent_ents[e].offsy += 0x0080;
  431.     if (ent_ents[e].offsy > 0x0800)
  432.       ent_ents[e].offsy = 0x0800;
  433.     return;
  434.       }
  435.       if (((ent_ents[e].x & 0x07) == 0x04) && (y < E_RICK_ENT.y)) {
  436.     /*sys_printf("e_them_t2 climbing00\n");*/
  437.     ent_ents[e].flgclmb = TRUE;  /* climbing */
  438.     return;
  439.       }
  440.     }
  441.  
  442.     /*sys_printf("e_them_t2 ymove nok or ...\n");*/
  443.     /* can't go there, or ... */
  444.     ent_ents[e].y = (ent_ents[e].y & 0xf8) | 0x03;  /* align to ground */
  445.     ent_ents[e].offsy = 0x0100;
  446.     if (ent_ents[e].latency != 00)
  447.       return;
  448.  
  449.     if ((env1 & MAP_EFLG_CLIMB) &&
  450.     ((ent_ents[e].x & 0x0e) == 0x04) &&
  451.     (ent_ents[e].y > E_RICK_ENT.y)) {
  452.       /*sys_printf("e_them_t2 climbing01\n");*/
  453.       ent_ents[e].flgclmb = TRUE;  /* climbing */
  454.       return;
  455.     }
  456.  
  457.     /* calc new sprite */
  458.     ent_ents[e].sprite = ent_ents[e].sprbase +
  459.       ent_sprseq[(ent_ents[e].offsx < 0 ? 4 : 0) +
  460.         ((ent_ents[e].x & 0x0e) >> 3)];
  461.     /*sys_printf("e_them_t2 sprite %02x\n", ent_ents[e].sprite);*/
  462.  
  463.  
  464.     /* */
  465.     if (ent_ents[e].offsx == 0)
  466.       ent_ents[e].offsx = 2;
  467.     x = ent_ents[e].x + ent_ents[e].offsx;
  468.     /*sys_printf("e_them_t2 xmove x=%02x\n", x);*/
  469.     if (x < 0xe8) {
  470.       u_envtest(x, ent_ents[e].y, FALSE, &env0, &env1);
  471.       if (!(env1 & (MAP_EFLG_VERT|MAP_EFLG_SOLID|MAP_EFLG_SPAD|MAP_EFLG_WAYUP))) {
  472.     ent_ents[e].x = x;
  473.     if ((x & 0x1e) != 0x08)
  474.       return;
  475.  
  476.     /*
  477.      * Black Magic (tm)
  478.      *
  479.      * this is obviously some sort of randomizer to define a direction
  480.      * for the entity. it is an exact copy of what the assembler code
  481.      * does but I can't explain.
  482.      */
  483.     bx = e_them_rndnbr + *sh + *sl + 0x0d;
  484.     cx = *sh;
  485.     *bl ^= *ch;
  486.     *bl ^= *cl;
  487.     *bl ^= *bh;
  488.     e_them_rndnbr = bx;
  489.  
  490.     ent_ents[e].offsx = (*bl & 0x01) ? -0x02 : 0x02;
  491.  
  492.     /* back to normal */
  493.  
  494.     return;
  495.  
  496.       }
  497.     }
  498.  
  499.     /* U-turn */
  500.     /*sys_printf("e_them_t2 u-turn\n");*/
  501.     if (ent_ents[e].offsx == 0)
  502.       ent_ents[e].offsx = 2;
  503.     else
  504.       ent_ents[e].offsx = -ent_ents[e].offsx;
  505. #undef offsx
  506. }
  507.  
  508. /*
  509.  * Action function for e_them _t2 type
  510.  *
  511.  * ASM 2718
  512.  */
  513. void
  514. e_them_t2_action(U8 e)
  515. {
  516.   e_them_t2_action2(e);
  517.  
  518.   /* they kill rick */
  519.   if (e_rick_boxtest(e))
  520.     e_rick_gozombie();
  521.  
  522.   /* lethal entities kill them */
  523.   if (u_themtest(e)) {
  524.     e_them_gozombie(e);
  525.     return;
  526.   }
  527.  
  528.   /* bullet kills them */
  529.   if (E_BULLET_ENT.n &&
  530.       u_fboxtest(e, E_BULLET_ENT.x + (e_bullet_offsx < 0 ? 00 : 0x18),
  531.          E_BULLET_ENT.y)) {
  532.     E_BULLET_ENT.n = 0;
  533.     e_them_gozombie(e);
  534.     return;
  535.   }
  536.  
  537.   /* bomb kills them */
  538.   if (e_bomb_lethal && e_bomb_hit(e)) {
  539.     e_them_gozombie(e);
  540.     return;
  541.   }
  542.  
  543.   /* rick stops them */
  544.   if (E_RICK_STTST(E_RICK_STSTOP) &&
  545.       u_fboxtest(e, e_rick_stop_x, e_rick_stop_y))
  546.     ent_ents[e].latency = 0x14;
  547. }
  548.  
  549.  
  550. /*
  551.  * Action sub-function for e_them _t3
  552.  *
  553.  * FIXME always starts asleep??
  554.  *
  555.  * Waits until triggered by something, then execute move steps from
  556.  * ent_mvstep with sprite from ent_sprseq. When done, either restart
  557.  * or disappear.
  558.  *
  559.  * Not always lethal ... but if lethal, kills rick.
  560.  *
  561.  * ASM: 255A
  562.  */
  563. void
  564. e_them_t3_action2(U8 e)
  565. {
  566. #define sproffs c1
  567. #define step_count c2
  568.   U8 i;
  569.   S16 x, y;
  570.  
  571.   while (1) {
  572.  
  573.     /* calc new sprite */
  574.     i = ent_sprseq[ent_ents[e].sprbase + ent_ents[e].sproffs];
  575.     if (i == 0xff)
  576.       i = ent_sprseq[ent_ents[e].sprbase];
  577.     ent_ents[e].sprite = i;
  578.  
  579.     if (ent_ents[e].sproffs != 0) {  /* awake */
  580.  
  581.       /* rotate sprseq */
  582.       if (ent_sprseq[ent_ents[e].sprbase + ent_ents[e].sproffs] != 0xff)
  583.     ent_ents[e].sproffs++;
  584.       if (ent_sprseq[ent_ents[e].sprbase + ent_ents[e].sproffs] == 0xff)
  585.     ent_ents[e].sproffs = 1;
  586.  
  587.       if (ent_ents[e].step_count < ent_mvstep[ent_ents[e].step_no].count) {
  588.     /*
  589.      * still running this step: try to increment x and y while
  590.      * checking that they remain within boudaries. if so, return.
  591.      * else switch to next step.
  592.      */
  593.     ent_ents[e].step_count++;
  594.     x = ent_ents[e].x + ent_mvstep[ent_ents[e].step_no].dx;
  595.  
  596.     /* check'n save */
  597.     if (x > 0 && x < 0xe8) {
  598.       ent_ents[e].x = x;
  599.       /*FIXME*/
  600.       /*
  601.       y = ent_mvstep[ent_ents[e].step_no].dy;
  602.       if (y < 0)
  603.         y += 0xff00;
  604.       y += ent_ents[e].y;
  605.       */
  606.       y = ent_ents[e].y + ent_mvstep[ent_ents[e].step_no].dy;
  607.       if (y > 0 && y < 0x0140) {
  608.         ent_ents[e].y = y;
  609.         return;
  610.       }
  611.     }
  612.       }
  613.  
  614.       /*
  615.        * step is done, or x or y is outside boundaries. try to
  616.        * switch to next step
  617.        */
  618.       ent_ents[e].step_no++;
  619.       if (ent_mvstep[ent_ents[e].step_no].count != 0xff) {
  620.     /* there is a next step: init and loop */
  621.     ent_ents[e].step_count = 0;
  622.       }
  623.       else {
  624.     /* there is no next step: restart or deactivate */
  625.     if (!E_RICK_STTST(E_RICK_STZOMBIE) &&
  626.         !(ent_ents[e].flags & ENT_FLG_ONCE)) {
  627.       /* loop this entity */
  628.       ent_ents[e].sproffs = 0;
  629.       ent_ents[e].n &= ~ENT_LETHAL;
  630.       if (ent_ents[e].flags & ENT_FLG_LETHALR)
  631.         ent_ents[e].n |= ENT_LETHAL;
  632.       ent_ents[e].x = ent_ents[e].xsave;
  633.       ent_ents[e].y = ent_ents[e].ysave;
  634.       if (ent_ents[e].y < 0 || ent_ents[e].y > 0x140) {
  635.         ent_ents[e].n = 0;
  636.         return;
  637.       }
  638.     }
  639.     else {
  640.       /* deactivate this entity */
  641.       ent_ents[e].n = 0;
  642.       return;
  643.     }
  644.       }
  645.     }
  646.     else {  /* ent_ents[e].sprseq1 == 0 -- waiting */
  647.  
  648.       /* ugly GOTOs */
  649.  
  650.       if (ent_ents[e].flags & ENT_FLG_TRIGRICK) {  /* reacts to rick */
  651.     /* wake up if triggered by rick */
  652.     if (u_trigbox(e, E_RICK_ENT.x + 0x0C, E_RICK_ENT.y + 0x0A))
  653.       goto wakeup;
  654.       }
  655.  
  656.       if (ent_ents[e].flags & ENT_FLG_TRIGSTOP) {  /* reacts to rick "stop" */
  657.     /* wake up if triggered by rick "stop" */
  658.     if (E_RICK_STTST(E_RICK_STSTOP) &&
  659.         u_trigbox(e, e_rick_stop_x, e_rick_stop_y))
  660.       goto wakeup;
  661.       }
  662.  
  663.       if (ent_ents[e].flags & ENT_FLG_TRIGBULLET) {  /* reacts to bullets */
  664.     /* wake up if triggered by bullet */
  665.     if (E_BULLET_ENT.n && u_trigbox(e, e_bullet_xc, e_bullet_yc)) {
  666.       E_BULLET_ENT.n = 0;
  667.       goto wakeup;
  668.     }
  669.       }
  670.  
  671.       if (ent_ents[e].flags & ENT_FLG_TRIGBOMB) {  /* reacts to bombs */
  672.     /* wake up if triggered by bomb */
  673.     if (e_bomb_lethal && u_trigbox(e, e_bomb_xc, e_bomb_yc))
  674.       goto wakeup;
  675.       }
  676.  
  677.       /* not triggered: keep waiting */
  678.       return;
  679.  
  680.       /* something triggered the entity: wake up */
  681.       /* initialize step counter */
  682.     wakeup:
  683.       if E_RICK_STTST(E_RICK_STZOMBIE)
  684.     return;
  685. #ifdef ENABLE_SOUND
  686.         /*
  687.         * FIXME the sound should come from a table, there are 10 of them
  688.         * but I dont have the table yet. must rip the data off the game...
  689.         * FIXME is it 8 of them, not 10?
  690.         * FIXME testing below...
  691.         */
  692.         syssnd_play(WAV_ENTITY[(ent_ents[e].trigsnd & 0x1F) - 0x14], 1);
  693.         /*syssnd_play(WAV_ENTITY[0], 1);*/
  694. #endif
  695.       ent_ents[e].n &= ~ENT_LETHAL;
  696.       if (ent_ents[e].flags & ENT_FLG_LETHALI)
  697.     ent_ents[e].n |= ENT_LETHAL;
  698.       ent_ents[e].sproffs = 1;
  699.       ent_ents[e].step_count = 0;
  700.       ent_ents[e].step_no = ent_ents[e].step_no_i;
  701.       return;
  702.     }
  703.   }
  704. #undef step_count
  705. }
  706.  
  707.  
  708. /*
  709.  * Action function for e_them _t3 type
  710.  *
  711.  * ASM 2546
  712.  */
  713. void
  714. e_them_t3_action(U8 e)
  715. {
  716.   e_them_t3_action2(e);
  717.  
  718.   /* if lethal, can kill rick */
  719.   if ((ent_ents[e].n & ENT_LETHAL) &&
  720.       !E_RICK_STTST(E_RICK_STZOMBIE) && e_rick_boxtest(e)) {  /* CALL 1130 */
  721.     e_rick_gozombie();
  722.   }
  723. }
  724.  
  725. /* eof */
  726.  
  727.  
  728.